package cc.magicjson.summary.errors.connection.closed.controller.message;


import cc.magicjson.summary.errors.connection.closed.service.message.producer.MessageProducer;
import org.springframework.web.bind.annotation.*;

import javax.jms.Queue;

@RestController
@RequestMapping("/api/messages")
public class MessageController {

    private final MessageProducer messageProducer;

    private final Queue queue;

    public MessageController(MessageProducer messageProducer, Queue queue) {
        this.messageProducer = messageProducer;
        this.queue = queue;
    }

    /**
     * 发送消息接口
     *
     * @param message 消息内容
     * @return 发送结果
     */
    @PostMapping("/send")
    public String sendMessage(@RequestParam String message) {
        messageProducer.sendMessage(queue, message);
        return "消息已发送: " + message;
    }
}
